<?php	require_once(dirname(__FILE__).'/inc/config.inc.php');IsModelPriv('soft');

/*
**************************
(C)2010-2015 phpMyWind.com
update: 2014-5-30 17:40:45
person: Feng
**************************
*/


//初始化参数
$tbname = '#@__soft';
$gourl  = 'soft.php';
$action = isset($action) ? $action : '';


//添加软件信息
if($action == 'add')
{
	if ($_POST['lan'] == 'zh')
	{
		$classid = '6';
	}
	else
	{
		$classid = '7';
	}

	//初始化参数
	if(!isset($mainid))        $mainid = '-1';

	//获取parentstr
	$row = $dosql->GetOne("SELECT `parentid` FROM `#@__infoclass` WHERE `id`=$classid");
	$parentid = $row['parentid'];

	if($parentid == 0)
	{
		$parentstr = '0,';
	}
	else
	{
		$r = $dosql->GetOne("SELECT `parentstr` FROM `#@__infoclass` WHERE `id`=$parentid");
		$parentstr = $r['parentstr'].$parentid.',';
	}

	$posttime = GetMkTime($posttime);

	//自定义字段处理
	$fieldname  = '';
	$fieldvalue = '';
	$fieldstr   = '';

	$sql = "INSERT INTO `$tbname` (siteid, classid, parentid, parentstr, mainid, mainpid, title, content, orderid, hits, posttime, checkinfo {$fieldname}) VALUES ('$cfg_siteid', '$classid', '$parentid', '$parentstr', '$mainid', '-1', '$title', '$content', '$orderid', '$hits', '$posttime', '$checkinfo' {$fieldvalue})";
	if($dosql->ExecNoneQuery($sql))
	{
		header("location:$gourl");
		exit();
	}
}


//修改软件信息
else if($action == 'update')
{
	$posttime = GetMkTime($posttime);

	//判断是否上传了pdf
	if($_FILES['picurl']['error'] == 0)
	{
		//判断是否是通过HTTP POST上传的
		if(!is_uploaded_file($_FILES['picurl']['tmp_name']))
		{
			return('非法上传');
		}

		//开始移动文件到相应的文件夹
		$upload_path = "../uploads/pdf/".date('Ymd'); //上传文件的存放路径
		if (!file_exists($upload_path)) //检查文件是否存在
		{
			mkdir($upload_path);
		}

		//移动文件
		$picurl = $upload_path.'/'.time().'.pdf';
		move_uploaded_file($_FILES['picurl']['tmp_name'],$picurl);
		$picurl = substr($picurl,3);
	}
	elseif($_FILES['picurl']['error'] == 1)
	{
		echo"<script>alert('文件过大,最大2MB');history.go(-1);</script>";
	}
	elseif ($_FILES['picurl']['error'] == 4)
	{
		$picurl = $_POST['picurl_bak'];
	}
	else
	{
		echo"<script>alert('上传失败,请重试');history.go(-1);</script>";
	}

	//自定义字段处理
	$fieldname  = '';
	$fieldvalue = '';
	$fieldstr   = '';

	$sql = "UPDATE `$tbname` SET title='$title', content='$picurl', orderid='$orderid', hits='$hits', posttime='$posttime', checkinfo='$checkinfo' {$fieldstr} WHERE id=$id";
	if($dosql->ExecNoneQuery($sql))
	{
		header("location:$gourl");
		exit();
	}
}


//修改审核状态
else if($action == 'check')
{
	//审核权限
	$r = $dosql->GetOne("SELECT `classid` FROM `#@__soft` WHERE `id`=$id");
	IsCategoryPriv($r['classid'],'update');


	if($checkinfo == '已审')
	{
		$dosql->ExecNoneQuery("UPDATE `$tbname` SET `checkinfo`='false' WHERE `id`=$id");
		echo '<a href="javascript:;" onclick="CheckInfo('.$id.',\'未审\')" title="点击进行审核与未审操作">未审</a>';
		exit();
	}

	if($checkinfo == '未审')
	{
		$dosql->ExecNoneQuery("UPDATE `$tbname` SET `checkinfo`='true' WHERE `id`=$id");
		echo '<a href="javascript:;" onclick="CheckInfo('.$id.',\'已审\')" title="点击进行审核与未审操作">已审</a>';
		exit();
	}
}


//无状态返回
else
{
	header("location:$gourl");
	exit();
}
?>
